﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Obligatorio.DataAccess;
using System.Data.Objects.DataClasses;

/// <summary>
/// Summary description for CreateUserPresenter
/// </summary>
public class CreateUserPresenter
{
    #region Field
    ICreateUserView _view;
    #endregion
    public CreateUserPresenter(ICreateUserView view)
    {
        this._view = view;
    }
    public void CreateUser()
    {
        using (var data = new ObligatorioDotNetEntities())
        {
            User user = new User()
            {
                BranchId = 1,
                UserName = this._view.UserName,
                UserPassword = Utils.GetMD5(this._view.Password)
            };

            var role = data.Roles.Where(r => r.RoleName == "Web").Single();
            user.Roles.Add(role);
            data.Users.AddObject(user);

            data.SaveChanges();
        }
    }
}